<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv=X-UA-Compatible content="IE=edge,chrome=1">
    <meta content=always name=referrer>
    <link rel="stylesheet" type="text/css" href="__STATIC__/css/newbase.css">
    <script src="__STATIC__/js/jquery-1.8.2.js"></script>
    <script src="__STATIC__/password/passwordBox.min.js"></script>
    <script src="__STATIC__/password/md5.js"></script>
    <title>充值VIP会员</title>
</head>
<body>

<div class="wrap-shop">
    <div class="header">
        <p>充值VIP会员</p>
        <img src="__STATIC__/img/back.png" class="back" onclick="back_url()">
        <span><a href="javascript:confirm_recharge()">确认充值</a></span>
    </div>
    <div class="center">
        <div>
            <h4>充值方式</h4>
            <div class="pay_center">
                <ul>
                    {eq name="is_weixin" value="1"}
                    <li>
                        <label for="radio-1-3"><img src="__STATIC__/img_user/zf-weixin.png"><span> 微信</span></label>
                        <input type="radio" id="radio-1-3" name="radio-1-set" class="radio" value="2" checked />
                    </li>
                    {/eq}
                    {eq name="is_weixin" value="2"}
                    <li>
                        <label for="radio-1-2"><img src="__STATIC__/img_user/zf-hifubao.png"><span> 支付宝</span></label>
                        <input type="radio" id="radio-1-2" name="radio-1-set" class="radio" value="1" />
                    </li>
                    {/eq}
                </ul>
            </div>
        </div>
        <div id="alipay" hidden></div>
    </div>
</div>
<script src="__STATIC__/js/layer_mobile/layer.js"></script>
<script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script>
    function confirm_recharge(){
        var price = 1;
        var pay_type = $("[type='radio']:checked").val();

        //支付宝充值
        if (pay_type == 1){
            $.ajax({
                url : "{:url('mobile/alipay/rechage')}",
                type:'post',
                dataType:'html',
                data:{'price':price,'body' : '{$information}' , 'order_number':'{$order_number}'},
                success:function (data) {
                    $('#alipay').html(data);
                },
                error: function () {
                    layer.open({content:'网络繁忙,请重试',skin:'msg',time:2});
                }
            })
        } else if (pay_type == 2){
            //微信充值
            window.location.href = "{:url('mobile/user_info/recharge_vip')}?pay_money="+price;
        }
    }
    //返回路径
    function back_url(){
        window.location.href = sessionStorage.getItem('recharge_back_url');
    }

    if (window.location.href.indexOf('pay_money') > -1){
        callpay();
    }

    function callpay() {
        if (typeof WeixinJSBridge == "undefined") {
            if (document.addEventListener) {
                document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
            } else if (document.attachEvent) {
                document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
                document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
            }
        } else {
            onBridgeReady(data);
        }
    }
    function onBridgeReady(){
        WeixinJSBridge.invoke(
                'getBrandWCPayRequest',JSON.parse('{$param}'),
                function(res){
//                    alert(res.err_msg);
                    if(res.err_msg == "get_brand_wcpay_request:ok" ) {
                        // 使用以上方式判断前端返回,微信团队郑重提示：res.err_msg将在用户支付成功后返回    ok，但并不保证它绝对可靠。
                        window.location.href = "{:url('mobile/user_info/recharge_vip')}";
                    }
                }
        );
    }
</script>
</body>
</html>